package com.zg.scf.web;

import com.zg.common.core.R;
import com.zg.common.core.dao.auth.AuthMenu;
import com.zg.common.core.exception.BusinessException;
import com.zg.common.web.Req;
import com.zg.scf.service.ScfMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"菜单管理"})
@RestController
@RequiredArgsConstructor
public class ScfMenuController {

    private final ScfMenuService scfMenuService;

    @ApiOperation("查询授权菜单")
    @GetMapping("/menu/listAuthMenu")
    public R<List<AuthMenu>> listAuthMenu(Long roleId) {
        if (roleId == null) {
            BusinessException.happen("请选择正确的角色");
        }
        List<AuthMenu> list = scfMenuService.listAuthMenu(roleId);
        return R.success(list);
    }

    @ApiOperation("查询登录用户菜单")
    @GetMapping("/menu/listByCurrUser")
    public R<List<AuthMenu>> listByCurrUser() {
        Long userId = Req.getCurrUser().getId();
        List<AuthMenu> list = scfMenuService.listByUserId(userId);
        return R.success(list);
    }
}
